// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   PropertyConfigParser.java

package conf;

import java.io.*;
import java.net.URL;
import java.util.Properties;

public class PropertyConfigParser
{

    public PropertyConfigParser()
    {
    }

    public static Properties loadConfigFile(String file)
        throws IOException
    {
        PropertyConfigParser parser = new PropertyConfigParser();
        return parser.parsePropertyFile(file);
    }

    public static Properties loadABSConfigFile(String absFilePath)
        throws IOException
    {
        PropertyConfigParser parser = new PropertyConfigParser();
        return parser.parseConfigFile(absFilePath);
    }

    public static void storePropertyFile(String file, Properties props, String header)
        throws IOException
    {
        PropertyConfigParser parser = new PropertyConfigParser();
        parser.savePropertyFile(file, props, header);
        parser = null;
    }

    public Properties parsePropertyFile(String file)
        throws IOException
    {
        Properties props = new Properties();
        try
        {
//            java.io.InputStream propFile = PropertyConfigParser.class.getResourceAsStream(file);
        	java.io.InputStream propFile = new FileInputStream(new File(file));
        	props.load(propFile);
            return props;
        }
        catch(IOException e)
        {
            throw new IOException("\u6CA1\u6709\u627E\u5230\u6307\u5B9A\u7684\u914D\u7F6E\u6587\u4EF6:" + file);
        }
    }

    public Properties parseConfigFile(String absFilePath)
        throws IOException
    {
        try
        {
            Properties props = new Properties();
            File configFile = new File(absFilePath);
            FileInputStream fin = null;
            fin = new FileInputStream(configFile);
            props.load(fin);
            return props;
        }
        catch(FileNotFoundException ex)
        {
            throw new IOException("\u6307\u5B9A\u914D\u7F6E\u6587\u4EF6 '" + absFilePath + "' \u4E0D\u5B58\u5728\u6216\u4E0D\u53EF\u8BFB.");
        }
    }

    public void savePropertyFile(String file, Properties props, String header)
        throws IOException
    {
        URL url = getClass().getResource(file);
        if(url == null)
        {
            throw new IOException("\u6307\u5B9A\u6587\u4EF6\u4E0D\u5B58\u5728");
        } else
        {
            OutputStream os = new FileOutputStream(url.getFile());
            props.store(os, header);
            os.close();
            return;
        }
    }
}
